package yd.pr;

import android.app.Activity;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.TextView;

import java.lang.reflect.InvocationTargetException;

public class ListPropActivity extends Activity {
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_prop);

        /**
         * misc items
         */
        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);

        try {
            String value = String.valueOf(Util.ReflectionUtil.invokeStaticMethod("android.os.SystemProperties", "get",
                    new Util.ReflectionUtil.ParamInfo[]{
                            new Util.ReflectionUtil.ParamInfo(String.class, "ro.board.platform"),
                            new Util.ReflectionUtil.ParamInfo(String.class, "def_pf")
                    }));
            tv(R.id.tv_reflection).setText("value = " + value);
//            Log.e("", "wta value = " + value);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

        tv(R.id.tv_imei).setText(tm.getDeviceId());
        tv(R.id.tv_mac).setText(wm.getConnectionInfo().getMacAddress());
        tv(R.id.tv_android_id).setText(Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID));
        tv(R.id.tv_sim_operator_numeric).setText(tm.getSimOperator());
        tv(R.id.tv_sim_operator_name).setText(tm.getSimOperatorName());
        tv(R.id.tv_sim_country_iso).setText(tm.getSimCountryIso());
        tv(R.id.tv_sim_state).setText(String.valueOf(tm.getSimState()));
        try {
            tv(R.id.tv_phone_type).setText(String.valueOf(
                    Util.ReflectionUtil.invokeMethod(tm, "getCurrentPhoneType")));
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        tv(R.id.tv_network_operator_name).setText(tm.getNetworkOperatorName());
        tv(R.id.tv_network_operator_numeric).setText(tm.getNetworkOperator());
        tv(R.id.tv_network_country_iso).setText(tm.getNetworkCountryIso());
        tv(R.id.tv_network_roaming).setText(String.valueOf(tm.isNetworkRoaming()));
        try {
            tv(R.id.tv_network_type).setText((CharSequence) Util.ReflectionUtil.invokeMethod(tm, "getNetworkTypeName"));
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

        /**
         * build.prop items
         */
        tv(R.id.tv_model).setText(Build.MODEL);
        tv(R.id.tv_build_id).setText(Build.ID);
        tv(R.id.tv_display_id).setText(Build.DISPLAY);
        tv(R.id.tv_ver_increm).setText(Build.VERSION.INCREMENTAL);
        tv(R.id.tv_sdk).setText(Build.VERSION.SDK);

        tv(R.id.tv_code_name).setText(Build.VERSION.CODENAME);
        tv(R.id.tv_release_version).setText(Build.VERSION.RELEASE);
        tv(R.id.tv_date_utc).setText(String.valueOf(Build.TIME));
        tv(R.id.tv_build_type).setText(Build.TYPE);
        tv(R.id.tv_user).setText(Build.USER);

        tv(R.id.tv_host).setText(Build.HOST);
        tv(R.id.tv_tags).setText(Build.TAGS);
        tv(R.id.tv_brand).setText(Build.BRAND);
        tv(R.id.tv_produtct_name).setText(Build.PRODUCT);
        tv(R.id.tv_device).setText(Build.DEVICE);

        tv(R.id.tv_board).setText(Build.BOARD);
        tv(R.id.tv_cpu_abi).setText(Build.CPU_ABI);
        tv(R.id.tv_fingerprint).setText(Build.FINGERPRINT);
    }

    private TextView tv(int tvId) {
        return (TextView) findViewById(tvId);
    }
}
